package org.hgvc.webapp.ets.jsf.beans.agent;

import java.util.List;

import javax.faces.component.UIParameter;
import javax.faces.event.ActionEvent;

import org.hgvc.webapp.ets.bo.Agreement;
import org.hgvc.webapp.ets.bo.Member;
import org.hgvc.webapp.ets.spring.service.MemberService;
import org.jocsb.base.AbstractBean;
import org.jocsb.base.exception.BaseException;
import org.jocsb.base.util.FacesUtils;



public class AgentMemberAgreementMgmtBean extends AbstractBean {

	public final static String BEAN_NAME="agentMemberAgreementMgmtBean";
	public final static String NAV_LIST="agentMemberAgreementMgmt";
	private MemberService memberService;
	private Member member;
	private List<Agreement> agreementList;
	private Agreement agreement;
	
	
	public MemberService getMemberService() {
		return memberService;
	}

	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}

	public String navMemberAgreementMgmt(Member member){
		this.member = member;
		return NAV_LIST;
	}

	public List<Agreement> getAgreementList() {
		try{
			agreementList = memberService.getAgreementListByMemberId(member.getMemberId());
		}catch(BaseException ex){
			ex.printStackTrace();
			initErrorBean(ex);
		}
		return agreementList;
	}
	
	public void navViewPointActionListener(ActionEvent actionEvent){
		UIParameter param = (UIParameter)actionEvent.getComponent().findComponent("agreementId");
		String id = (String)param.getValue();
		for(Agreement agreement:agreementList){
			if(agreement.getAgreementId().equalsIgnoreCase(id)){
				this.agreement = agreement;
				break;
			}
		}
	}
	
	public String navViewPointAction(){
		AgentMemberAgreementPointEnquiryBean bean = (AgentMemberAgreementPointEnquiryBean)FacesUtils.getManagedBean(AgentMemberAgreementPointEnquiryBean.BEAN_NAME);
		return bean.navListAction(agreement);
	}
	
	public void navViewAgreementInvoiceActionListener(ActionEvent actionEvent){
		UIParameter param = (UIParameter)actionEvent.getComponent().findComponent("vagreementId");
		String id = (String)param.getValue();
		for(Agreement agreement:agreementList){
			if(agreement.getAgreementId().equalsIgnoreCase(id)){
				this.agreement = agreement;
				break;
			}
		}
	}
	
	public String navViewAgreementInvoiceAction(){
		AgentMemberAgreementInvoiceBean bean = (AgentMemberAgreementInvoiceBean)FacesUtils.getManagedBean(AgentMemberAgreementInvoiceBean.BEAN_NAME);
		return bean.navListAction(agreement);
	}
	
}
